package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FdStudent;
import com.ruoyi.system.service.IFdStudentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奋达学生Controller
 * 
 * @author ruoyi
 * @date 2021-07-06
 */
@Controller
@RequestMapping("/system/student")
public class FdStudentController extends BaseController
{
    private String prefix = "system/student";

    @Autowired
    private IFdStudentService fdStudentService;

    @RequiresPermissions("system:student:view")
    @GetMapping()
    public String student()
    {
        return prefix + "/student";
    }

    /**
     * 查询奋达学生列表
     */
    @RequiresPermissions("system:student:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FdStudent fdStudent)
    {
        startPage();
        List<FdStudent> list = fdStudentService.selectFdStudentList(fdStudent);
        return getDataTable(list);
    }

    /**
     * 导出奋达学生列表
     */
    @RequiresPermissions("system:student:export")
    @Log(title = "奋达学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FdStudent fdStudent)
    {
        List<FdStudent> list = fdStudentService.selectFdStudentList(fdStudent);
        ExcelUtil<FdStudent> util = new ExcelUtil<FdStudent>(FdStudent.class);
        return util.exportExcel(list, "奋达学生数据");
    }

    /**
     * 新增奋达学生
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存奋达学生
     */
    @RequiresPermissions("system:student:add")
    @Log(title = "奋达学生", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FdStudent fdStudent)
    {
        return toAjax(fdStudentService.insertFdStudent(fdStudent));
    }

    /**
     * 修改奋达学生
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FdStudent fdStudent = fdStudentService.selectFdStudentById(id);
        mmap.put("fdStudent", fdStudent);
        return prefix + "/edit";
    }

    /**
     * 修改保存奋达学生
     */
    @RequiresPermissions("system:student:edit")
    @Log(title = "奋达学生", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FdStudent fdStudent)
    {
        return toAjax(fdStudentService.updateFdStudent(fdStudent));
    }

    /**
     * 删除奋达学生
     */
    @RequiresPermissions("system:student:remove")
    @Log(title = "奋达学生", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fdStudentService.deleteFdStudentByIds(ids));
    }
}
